package com.weimin.ghostdrop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weimin.ghostdrop.entity.Links;
import com.weimin.ghostdrop.entity.dto.LinksDTO;
import com.weimin.ghostdrop.service.LinksService;
import com.weimin.ghostdrop.mapper.LinksMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* @author huimin
* @description 针对表【links(软件下载链接表)】的数据库操作Service实现
* @createDate 2025-10-11 10:38:47
*/
@Service
public class LinksServiceImpl extends ServiceImpl<LinksMapper, Links>
    implements LinksService{
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveOrUpdateBySid(Integer softwareId, LinksDTO dto) {
        Links links = this.lambdaQuery().eq(Links::getSid, softwareId).one();
        if (links == null) {
            links = new Links();
            links.setSid(softwareId);
            links.setBaidu(dto.getBaidu());
            links.setAliyun(dto.getAliyun());
            links.setXunlei(dto.getXunlei());
            links.setQuark(dto.getQuark());
            links.setLanzou(dto.getLanzou());
            this.save(links);
        } else {
            links.setBaidu(dto.getBaidu());
            links.setAliyun(dto.getAliyun());
            links.setXunlei(dto.getXunlei());
            links.setQuark(dto.getQuark());
            links.setLanzou(dto.getLanzou());
            this.updateById(links);
        }
    }

    @Override
    public Links getBySid(Integer softwareId) {
        return this.lambdaQuery().eq(Links::getSid, softwareId).one();
    }
}




